package com.taosdata.taosdemo.utils;

import com.alibaba.fastjson2.JSONObject;
import org.apache.commons.lang3.StringUtils;

import java.io.*;

/**
 * @author PC
 */
public class JsonConfig {
    public static void main(String[] args) {
        JsonConfig config = new JsonConfig();
        String str = config.read("insert.json");
        JSONObject jsonObject = null;
        if (StringUtils.isNotBlank(str)) {
            jsonObject = JSONObject.parseObject(str);
        }
        System.out.println(jsonObject);
    }

    private String read(String fileName) {
        try (InputStream inputStream = JsonConfig.class.getClassLoader().getResourceAsStream(fileName);
             InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
             BufferedReader bufferedReader = new BufferedReader(inputStreamReader)) {
            StringBuilder sb = new StringBuilder();
            String line = null;
            while ((line = bufferedReader.readLine()) != null) {
                sb.append(line);
            }
            return sb.toString();
        } catch (IOException e) {
            e.printStackTrace();
            return "";
        }
    }
}